import style from '@/assets/components.module.scss';

import {} from '@/components';
import { HttpResponse } from '@/utils';

export interface ProjectProps {
    children?: string | React.ReactElement | React.ReactElement[];
}

function Project({ children }: ProjectProps) {
    console.log(time().format('{YYYY} HH:mm:ss'), `comments render`);

    const history = withRouter();
    const id = localStorage.getItem('id');

    const { data } = useSwr<
        HttpResponse<
            {
                comt: {
                    text: string;
                    title: string;
                    createtime: string;
                };
                user: {
                    avatar: string;
                    name: string;
                    email: string;
                };
            }[]
        >
    >(`com?uid=${id}`, axios.get);

    return (
        <>
            <div className={style['space-comment']}>
                {data?.data.map((item) => (
                    <div className={style['space-block']} key={Math.random()}>
                        <div className={style['header']}>
                            <div className={style['avatar']}>
                                <img src={item.user.avatar} />
                            </div>
                            <div>
                                <p>
                                    <span className='mr-3 font-bold'>
                                        {item.user.name}
                                    </span>
                                    <span className='text-gray-500'>
                                        @{item.user.email}
                                    </span>
                                </p>
                                <p>{item.comt.createtime}</p>
                            </div>
                        </div>
                        <div>
                            <p>{item.comt.text}</p>
                        </div>
                    </div>
                ))}
            </div>
        </>
    );
}

export default Project;
